// Various commit functions
// TODO: modifyTag, composer

function dumbFunction (data) {}

function commitThreadAsRead (threadID) {
	callJSON ('/ui/commit/setThreadAsRead/' + threadID, dumbFunction);
}


function setThreadAsRead (threadID) {
//	return true;				// Dsiable it for debug
	var data = gData.currThreads[threadID];
	var numUnread = data.numUnread;

	// UI tricks for tag
	if (gData.currResource.substring(0, 3) == 'tag') {
		var tagName = gData.currResource.substring(4);
		var obj = gData.tagPool[tagName];
		obj.numUnread -= numUnread;
		if (obj.numUnread < 0) obj.numUnread = 0;
		renderTagLink(tagName);		
	}

	// Set the thread as read
	commitThreadAsRead(threadID);
	data.numUnread = 0;
	renderMessageTitle(threadID);
}


function commitTagAsRead (tagName) {
	callJSON ('/ui/commit/setTagAsRead/' + tagName, dumbFunction);
}

function setTagAsRead () {
	var resource = gData.currResource;
	if (resource.substring(0, 3) !=  'tag')
		return;

	var tagName = resource.substring(4);
	commitTagAsRead(tagName);
	// Refresh all
//	selectView(gData.currResource, gData.currPage);
	// UI Trick


	var obj = gData.tagPool[tagName];
	obj.numUnread = 0;	
	renderTagLink(tagName);

	for (threadID in gData.currThreads) {
		if (threadID == gData.openThread) {
			closeThread(threadID);
			gData.openThread = -1;
		}
		gData.currThreads[threadID].numUnread = 0;
		renderMessageTitle(threadID);
	}

}
